Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example code for each configuration to verify correctness during continuous integration #12

Merged

Conversation

mangs
Copy link
Contributor

@mangs mangs commented Jan 3, 2024

Pull Request Checklist

Changes Included

  • Version bump to 1.2.0
  • Testing added using example code for each configuration to verify correctness during continuous integration
  • React and Preact TypeScript configs now allow JSX in files with .tsx file extensions
  • Remove dev dependency npm-run-all because it was only used during the reinstall NPM script and would cause an error if dependencies weren't installed prior to execution

@mangs mangs marked this pull request as ready for review January 5, 2024 22:31
@mangs mangs requested a review from jduthon as a code owner January 5, 2024 22:31
Copy link
Contributor Author

@mangs mangs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes for context:

## 1.2.0

- Testing added using example code for each configuration to verify correctness during continuous integration
- React and Preact TypeScript configs now allow JSX in files with `.tsx` file extensions
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This improvement resulted from writing the tests

@@ -20,7 +20,7 @@

"overrides": [
{
"files": "*.{cjs,js,jsx,mjs,ts,tsx}",
"files": "*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally using .mts files when I started this work. I started off using Bun to write unit tests then settled on using example code and running ESLint against it because it was more informative and easier to identify the root cause of errors.

@@ -9,5 +9,7 @@
"browser": false,
"node": false
},
"rules": {}
"rules": {
"react/jsx-filename-extension": ["error", { "extensions": [".jsx", ".tsx"] }]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the improvement to the library that resulted from testing. The Preact Typescript config extends this config so it benefits from this too.

Comment on lines +63 to +75
"@playwright/test": "1.40.1",
"@types/aws-lambda": "8.10.131",
"@types/node": "20.10.6",
"@types/react": "18.2.46",
"@types/react-dom": "18.2.18",
"eslint": "8.56.0",
"jest": "29.7.0",
"preact": "10.19.3",
"prettier": "3.1.0",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.3.3"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only added dev dependencies necessary for these tests. I'll update non-dev dependencies in a separate PR to bring them up to their latest versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a huge time investment because every config extends from this one. I went one-by-one through every rule and tried to write code to tackle each, but it wasn't always possible. The most targeted rules ended up being the regex and unicorn ones.

Comment on lines +4 to +5
[ssr]
maintained Node versions
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During this process, I learned you can target SSR separately using Browserslist. Food for thought.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might look familiar 🙃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I was running low on time, I adapted the same example for the Preact, Preact TypeScript, React, and React TypeScript tests

Copy link

@jduthon jduthon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice work!

I think the last test examples are more similar to what I had imagined, basically they just allow to test that the config works overall (e.g. the eslint config is valid, it doesn't have broken parts and we can run it an ESLint check with it successfully).
The other one is interesting as it could give more safety, but I think it's quite hard to make it work correctly and maintain, so it might not be worth it I think.

Approving regardless of what we decide on the base tests, as ultimately I think they still do the job even though they might be a bit too complex or not necessarily 100% fulfilling their intended goals.

objectWithSortedKeys,
oneThousand,
printEslintConfig,
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite thorough work here, but I am not sure whether this actually tests the rule.
As an example, if I were to remove the rule unicorn/prefer-node-protocol, tests for this file would still pass, because it wouldn't break any new rules.
I guess one way we could check for those could be by disabling things, and then as long as we have "report unused disables", we would get warned in case something goes wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea this is a drawback to this approach. I had originally started with the ESLint API directly to be able to catch some negative cases (e.g. if a rule is disabled), but the way it reports back problems isn't very friendly so when I extrapolated the amount of work necessary to make it maintainable and easily understandable, I decided to just use the CLI which is far more friendly and what people are used to. Not perfect but a lot better than what was there before.

}

// Begin Execution
main();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this file I can see you haven't specified which rules different parts of the code tests, is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly did that for the base config, then when I was time boxing I wasn't as thorough. Apparently I didn't add any here.

@mangs mangs merged commit 58d8dff into babbel:main Jan 9, 2024
1 check passed
@mangs mangs deleted the PNAPL-366-add-correctness-checks-for-each-config branch January 9, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants